{% extends 'users/base.html' %}
{% block head %}<title>编辑文章</title>{% endblock head %}

{% block content %}
<div class="container">
  <section class="hero is-primary is-bold">
    <div class="hero-body">
      <div class="container">
        <div class="level">
          <div class="level-left">
            <h1 class="title">编辑文章</h1>
          </div>
          <div class="level-right">
            <a class="button" href="{% url 'users:article_list' %}">
              <span class="icon">
                <i class="fas fa-arrow-left"></i>
              </span>
              <span>返回文章列表</span>
            </a>
          </div>
        </div>
      </div>
    </div>
  </section>

  <div class="box" style="padding: 50px 80px; margin: 50px auto">
    <form method="post">
      {% csrf_token %}
      <div class="field">
        <label class="label">标题</label>
        <div class="control">
          <input class="input" type="text" name="title" value="{{ form.title.value|default_if_none:'' }}">
        </div>
      </div>

      <div class="field">
        <label class="label">描述</label>
        <div class="control">
          <textarea class="textarea" name="desc">{{ form.desc.value|default_if_none:'' }}</textarea>
        </div>
      </div>

      <div class="field">
        <label class="label">分类</label>
        <div class="control">
          <div class="select">
            <select name="category">
              {% for category in form.category.field.queryset %}
              <option value="{{ category.id }}" {% if category.id == form.category.value %}selected{% endif %}>{{ category }}</option>
              {% endfor %}
            </select>
          </div>
        </div>
      </div>

      <div class="field">
        <label class="label">内容</label>
        <div class="control">
          <textarea class="textarea" name="content">{{ form.content.value|default_if_none:'' }}</textarea>
        </div>
      </div>

      <div class="field">
        <label class="label">标签</label>
        <div class="control">
          {% for tag in form.tags.field.queryset %}
          <label class="checkbox">
            <input type="checkbox" name="tags" value="{{ tag.id }}" {% if tag.id in form.tags.value %}checked{% endif %}>
            {{ tag.name }}
          </label>
          {% endfor %}
        </div>
      </div>

      <div class="field is-grouped">
        <div class="control">
          <button type="submit" class="button is-primary">更新文章</button>
        </div>
        <div class="control">
          <a href="{% url 'users:article_list' %}" class="button is-light">取消</a>
        </div>
      </div>
    </form>
  </div>
</div>
{% endblock %}
